home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 493 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: dagwood.cs.ucsb.edu!not-for-mail
  2. From: schapel@cs.ucsb.edu (Steve E. Chapel)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: char* string problem
  5. Date: 5 Jan 1996 11:54:52 -0800
  6. Organization: Computer Science, UCSB
  7. Message-ID: <4cjvmc$1eq@dagwood.cs.ucsb.edu>
  8. References: <4ci7gu$68r@cloner3.netcom.com>
  9. NNTP-Posting-Host: dagwood.cs.ucsb.edu
  10.  
  11. tstevens@ix.netcom.com (Edward Stevens ) writes:
  12.  
  13. >    I need to prepend some switch characters to some strings passed 
  14. >to a main program which I have renamed for use as a function. 
  15.  
  16. >The calling program looks like this:
  17.  
  18. >char* the_args[4];
  19. >char* Aprefix = " -A";
  20. >char* Bprefix = " -B";
  21. >char* CPrefix = " -C";
  22. >char* Dprexix = " -D";
  23.  
  24. >the_args[0] = "user_name";
  25. >the_args[0] = strcat(Aprefix,the_args[0]);
  26.  
  27. Okay, you're putting "user_name" after the string " -A". But the string
  28. " -A" is stored in a location where there is no guarantee what comes after
  29. it, or that you can write into that space. How about something like:
  30.  
  31. char temp[80];    /* Plenty of space you can do anything with */
  32. strcpy(temp, Aprefix);
  33. strcat(temp, the_args[0]);
  34.  
  35. By defining temp as an array, you get to do whatever you like with it.
  36. -- 
  37. Steve Chapel        schapel@cs.ucsb.edu    |    http://www.cs.ucsb.edu/~schapel
  38.    Senior in Computer Science at the       |    Check out my updated web page!!
  39. University of California, Santa Barbara    |    finger -l schapel@eci1.ucsb.edu
  40. "I jumped, O my brothers, and I fell hard, but I did not snuff it." - Alex
  41.